<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Attachment extends Model
{
    use HasFactory;

    protected $fillable = [
        'uid',
        'filename',
        'attachment',
        'storage_type',
        'type'
    ];

    protected $appends = ['url'];

    public function getUrlAttribute()
    {
        $_url = '';
        if($this->storage_type != 'default') {
            $_setting = SettingMedia::value($this->storage_type);
            $_url = $_setting['domain'].'/'.$this->attachment;
        } else {
            $_url = config('app.url').'/storage/'.$this->attachment;
        }
        return $_url;
    }
}
